---
title: Value assigned to locals is not accepted.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
---

> **LocalsNotAnObject**: `locals` 只能被赋值为一个对象。不接受如数字、字符串等其他值。

## 哪里发生了错误？

当 `locals` 被赋值为一个非对象时抛出错误。

例如：

```ts
import { defineMiddleware } from "astro:middleware";
export const onRequest = defineMiddleware((context, next) => {
  context.locals = 1541;
  return next();
});
```
